import {Component} from 'angular2/core';
import {UserService} from '../services/user.service';
import {TaskService} from '../services/task.service';
import {User} from '../models/user';
import {Router} from 'angular2/router';
import {ROUTER_DIRECTIVES} from 'angular2/router';
import { TaskInfo } from '../models/taskInfo';


@Component({
  selector: 'my-task',
  templateUrl: 'app/components/my-sharedtask.component.html',
  directives: [ROUTER_DIRECTIVES]
})
export class MySharedTask {
  private tasks: TaskInfo[];
  private user;

  constructor (
    private router: Router,
    private userService: UserService,
    private taskService:TaskService
  ) {
    this.userService.getUserByName(localStorage.getItem("currentUserName")).subscribe(
      user => {
        this.user = JSON.parse(JSON.parse(JSON.stringify(user))._body);
        this.taskService.getSharedTasks(this.user).subscribe(
          tasks =>{
            
            this.tasks=JSON.parse(JSON.parse(JSON.stringify(tasks))._body);
            console.log(this.tasks)
          
          } 
         
        ),
        error => console.log(error)
        console.log(this.tasks);
      }
    ),
    error => console.log(error)
  };

  selectCheckbox(check:boolean,value:string){    
    if(check){   
    }
    else{

    }
  }

  onSelect(task: TaskInfo) {
    this.router.navigate(['UpdateTaskInfo', {id: task.taskId}]);
  }
 
}
